package com.dt76.smallloanfrontendservice.controller.etao;


import com.dt76.smallloanfrontendservice.pojo.etao.User;
import com.dt76.smallloanfrontendservice.service.etao.UserService;
import com.dt76.smallloanfrontendservice.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class LoginController {
    @Autowired
    private UserService userService;

    @RequestMapping("/doLogin")
    @ResponseBody
    public Result doLogin(@RequestParam String userName,
                          @RequestParam String password) {
        Result result = userService.findUserByLogin(userName, password);
        return result;
    }

    @RequestMapping("/doLoginByEmail")
    @ResponseBody
    public Result doLoginByEmail(@RequestParam String email) {
        Result result = userService.findUserByEmail(email);
        return result;
    }


    @RequestMapping("/insertUser")
    @ResponseBody
    public Result insertUser(@RequestBody User user) {
        Result result = new Result();
        result.setSuccess(userService.addUser(user));
        return result;
    }

}
